﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CivLib.CivNum
{

  static class Conv
  {
    /// <summary>
    /// Enumeration of convertible lengths
    /// </summary>
    public enum Len
    {
      m,
      cm,
      mm,
      km,
      ft,
      inch,
      yd,
      mile
    };

    /// <summary>
    /// Array of factors for conversion to meters
    /// </summary>
    static double[] LenConv = new double[]
    {
      1.0d,     //m
      1.0E-2d,  //cm
      1.0E-3d,  //mm
      1.0E+3d,  //km
      0.3048,   //ft (official value decided in 1958)
      0.0254,   //inch
      0.9144,   //yd
      1609.344  //mile
    };

    public static double LenC(double a_length, Len a_from, Len a_to)
    {
      return a_length * LenConv[(int)a_from] / LenConv[(int)a_to];
    }

    public enum Area
    {
      m2,
      cm2,
      mm2,
      km2,
      ft2,
      inch2,
      yd2,
      mile2,
      Acre
    };

    /// <summary>
    /// Array of factors for conversion to square meters
    /// </summary>
    static double[] AreaConv = new double[]
    {
      1.0d,               //m2
      1.0E-4d,            //cm2
      1.0E-6d,            //mm2
      1.0E+6d,            //km2
      9.290304E-2d,       //ft2 
      6.4516E-4d,         //inch2
      0.83612736d,        //yd2
      2,589,988.110336d,  //mile2
      4046.8564224        //Acre
    };

    public static double AreaC(double a_area, Area a_from, Area a_to)
    {
      return a_area * AreaConv[(int)a_from] / AreaConv[(int)a_to];
    }

  }
}
